<template>
  <div>
    <main>
      <div class="title">
        <div class="tips">
          <div class="bt">{{courseDetails.name}}</div>
          <div class="ts">
          
          </div>
        </div>
        <div class="allcourse">
          <div class="num">
            <span v-if="courseDetails.num != null">{{
              courseDetails.num == null ? "0" : courseDetails.num
            }}</span>
            人已看
          </div>
          <router-link to="/basecourselist" class="total">全部课程</router-link>
        </div>
      </div>
      <div class="video">
        <video-player
          class="video-player-box"
          ref="videoPlayer"
          :options="playerOptions"
          :playsinline="true"
          customEventName="customstatechangedeventname"
          @play="onPlayerPlay($event)"
          @pause="onPlayerPause($event)"
          @ended="onPlayerEnded($event)"
          @ready="playerReadied"
        >
        </video-player>
      </div>
      <div class="txt">
        {{ courseDetails.content}}
      </div>
    </main>
  </div>
</template>

<script>
import 'video.js/dist/video-js.css'
import { videoPlayer } from 'vue-video-player'
import api from '@/config/api'
import { sendPost } from '@/utils/http'
export default {
  name: 'Ptebase',
  components: {
    videoPlayer
  },
  data () {
    return {
      playerOptions: {
        // videojs options
        muted: true,
        language: 'zh-CN',
        playbackRates: [0.7, 1.0, 1.5, 2.0],
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。
        sources: [{
          type: 'video/mp4',
          src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm'
        }],
        poster: "" // 你的封面地址
      },
      courseDetails: {},
    }
  },
  created () {
    this.getCourseDetails()
  },
  computed: {
    player () {
      return this.$refs.videoPlayer.player
    }
  },
  methods: {
    // 获取课程详情
    getCourseDetails () {
      sendPost(api.getCourseVideoUrl, { id: this.$route.query.id}).then(res => {
        console.log(res);
        this.courseDetails = res.data
        // this.playerOptions.poster = res.data.image
        this.playerOptions.sources[0].src = res.data.url
      })
    },
    // listen event
    onPlayerPlay (player) {
      // console.log('player play!', player)
    },
    onPlayerPause (player) {
      // console.log('player pause!', player)
    },
    // ...player event

    // or listen state event
    playerStateChanged (playerCurrentState) {
      // console.log('player current update state', playerCurrentState)
    },

    // player is ready
    playerReadied (player) {
      // console.log('the player is readied', player)
      // you can use it to do something...
      // player.[methods]
    }
  }
}
</script>

<style>
body,
html {
  background-color: #fff;
}
</style>
<style lang="less" scoped>
// /deep/.video-js .vjs-control-bar {
//   background: linear-gradient(0deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0)) !important;
//   height: 100px !important;
//   padding: 23px 23px;
// }
// /deep/.vjs-button > .vjs-icon-placeholder:before{
//   font-size: 1.375rem;
// }
main {
  width: 75rem;
  margin: auto;
  .title {
    height: 8.75rem;
    padding-top: 3.4375rem;
    box-sizing: border-box;
    display: flex;
    .allcourse {
      width: 10rem;
      height: 4.375rem;
      width: 10rem;
      .num {
        height: 1.25rem;
        text-align: center;
        span {
          color: #ff5e4e;
        }
      }
      .total {
        display: inline-block;
        text-decoration: none;
        width: 10rem;
        height: 3.125rem;
        line-height: 3.125rem;
        text-align: center;
        background-color: #ff5e4e;
        border-radius: 0.625rem;
        font-size: 1.25rem;
        color: #fff;
        margin-top: 0.1875rem;
      }
    }
    .tips {
      flex: 1;
      .bt {
        font-size: 2rem;
        color: #333;
        line-height: 2rem;
      }
      .ts {
        font-size: 1rem;
        color: #999;
        line-height: 2.5rem;
      }
    }
  }
  .video {
    height: 42.25rem;
    position: relative;
    #vjs_video_3 {
      width: 100%;
    }
    /deep/.video-js .vjs-big-play-button {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }
  .txt {
    height: 23.4375rem;
    margin: 3.125rem 0;
    color: #666;
    line-height: 2rem;
    font-size: 1rem;
    margin-bottom: 5rem;
  }
}
</style>
